package com.liy.framework.web.spring.controller;

import com.liy.framework.common.extvo.ApiRequestVO;
import com.liy.framework.common.extvo.ResponseVo;
import com.liy.framework.common.utils.Tools;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class ApiSupportController {

    protected static Logger log = LoggerFactory.getLogger(ApiSupportController.class);

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    public ApiSupportController() {}

    protected String getRequestParameter(String key) {
        return this.request.getParameter(key);
    }

    /** @deprecated */
    @Deprecated
    protected ResponseVo valid(ApiRequestVO<?> vo) {
        return this.valid(vo, false);
    }

    /** @deprecated */
    @Deprecated
    protected ResponseVo valid(ApiRequestVO<?> vo, boolean validParams) {
        if (!Tools.StringIsNullOrSpace(vo.getEquId()) && vo.getEquId().length() == 9) {
            if (!Tools.StringIsNullOrSpace(vo.getAuthId()) && vo.getAuthId().length() == 32) {
                if (!Tools.StringIsNullOrSpace(vo.getVersion()) && vo.getVersion().length() <= 6) {
                    if (!Tools.StringIsNullOrSpace(vo.getTimestamp()) && vo.getTimestamp().length() == 14) {
                        return validParams && vo.getParams() == null ? ResponseVo.error("99", "数据校验失败，请求参数不完整") : ResponseVo.success();
                    } else {
                        return ResponseVo.error("99", "数据校验失败，非法的日期格式");
                    }
                } else {
                    return ResponseVo.error("03", "数据校验失败，无效的版本号");
                }
            } else {
                return ResponseVo.error("02", "数据校验失败，设备认证码错误");
            }
        } else {
            return ResponseVo.error("01", "数据校验失败，非法的设备编号");
        }
    }
}
